package email;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.File;

import javax.swing.JTable;

public class UserMouseOperation implements MouseListener {
	private MainDialog mainDialog;

	public UserMouseOperation(MainDialog mainDialog) {
		this.mainDialog = mainDialog;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		JTable m_table = mainDialog.getTable();
		if (e.getClickCount() == 1) {
			//m_table.setRowSelecionInterval()
			System.out.println("单击！");
		} else if (e.getClickCount() == 2) {
			int rowIndex = m_table.rowAtPoint(e.getPoint());// 得到table的行号
			int columnIndex = m_table.columnAtPoint(e.getPoint());
			Object value = m_table.getValueAt(rowIndex, columnIndex);
			FileManager fileManager = mainDialog.getFileManager();
			if (((String) value).equals("..")) {
				FileManager.currentDirectory = FileManager.currentDirectory.getParentFile();
				fileManager.init();
				fileManager.display();
				return;
			}
			
			File file = fileManager.getAllFiles().get(rowIndex);
			if (file.isDirectory()) {
				FileManager.currentDirectory = file;
			}
			fileManager.init();
			fileManager.display();
			System.out.println(value);
		} else if (e.getClickCount() == 3) {
			System.out.println("三连击！！");
		}
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		if (e.getButton() == 3) {
			mainDialog.createPopupMenu(e.getX(), e.getY());
		}
	}
}
